/**
 * Copyright (c) 2015-2016, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.txzt.gaea.common.util;

import com.txzt.base.constant.RtnConstant;
import com.txzt.base.core.RtnInfo;
import com.txzt.base.util.SpringContextHolder;
import com.txzt.gaea.api.client.AdminRemoteService;
import com.txzt.gaea.common.constant.Constants;
import com.txzt.gaea.common.core.base.context.AdminUserContext;
import com.txzt.gaea.dto.HasAuthDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 高频方法集合类
 */
@Component
public class AuthUtil {
    @Autowired
    private AdminRemoteService adminRemoteService;

    /**
     * 是否有权限
     * @param code
     * @return
     */
    public boolean hasAuth(String code){
        HasAuthDTO hasAuthDTO = HasAuthDTO.builder().authCode(code).userId(AdminUserContext.getUser().getId()).build();
        hasAuthDTO.setToolCode(Constants.TOOL_CODE);
        hasAuthDTO.setToolVersion(Constants.TOOL_VERSION);
        RtnInfo<Boolean> rtnInfo = adminRemoteService.hasAuth(hasAuthDTO);
        if(RtnConstant.Code.SUCCESS_CODE.equals(rtnInfo.getCode())){
            return rtnInfo.getData();
        }
        return false;
    }
}
